package worldinruin.gui.imp.gameview;

import javax.swing.Action;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;

import worldinruin.controllers.ControlFactory;
import worldinruin.controllers.ControlFactory.Controllers;
import worldinruin.core.IBuilding;
import worldinruin.resources.Components;
import worldinruin.resources.IconMap;
import worldinruin.resources.Keys;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class BuildingPanel extends javax.swing.JPanel {
	
	private JLabel buildingIconLabel;
	private JButton buildButton;
	private ResourcePricePanel resourcePanel;
	private Action listener;
	private IBuilding building;
	
	
	/**
	 * Creates a building panel that can build.
	 * @param building Building that can be built.
	 */
	public BuildingPanel(IBuilding building) {
		super();
		this.building = building;
		setupGUI();
		initListener();
	}
	
	/**
	 * Initiate listeners to components.
	 */
	private void initListener() {
		listener = ControlFactory.getControl(Controllers.GAMEBOARD_CONTROLLER);
		buildButton.addActionListener(listener);
		listener.putValue(Components.buildBuildingButton, buildButton);
		listener.putValue(Keys.BUILDINGKEY.toString(), building);
		
	}

	/**
	 * Setup GUI.
	 */
	private void setupGUI() {
		
		{
			buildingIconLabel = new JLabel();
			buildingIconLabel.setIcon(IconMap.getInstance().getIcon(building.getBuildingType()));
			buildingIconLabel.setOpaque(true);
			buildingIconLabel.setVisible(true);
		}
	

			
			resourcePanel = new ResourcePricePanel(building.getPrice());

			resourcePanel.setPreferredSize(new java.awt.Dimension(191, 50));

		{
			buildButton = new JButton();
			buildButton.setText("Build");
		}		
		
		GroupLayout thisLayout = new GroupLayout((JComponent)this);
		this.setLayout(thisLayout);
			thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
				.addContainerGap(19, 19)
				.addComponent(buildingIconLabel, GroupLayout.PREFERRED_SIZE, 105, GroupLayout.PREFERRED_SIZE)
				.addGap(32)
				.addComponent(resourcePanel, GroupLayout.PREFERRED_SIZE, 57, GroupLayout.PREFERRED_SIZE)
				.addGap(0, 42, Short.MAX_VALUE)
				.addComponent(buildButton, GroupLayout.PREFERRED_SIZE, 43, GroupLayout.PREFERRED_SIZE)
				.addContainerGap());
			thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
				.addContainerGap(25, 25)
				.addGroup(thisLayout.createParallelGroup()
				    .addGroup(thisLayout.createSequentialGroup()
				        .addComponent(buildingIconLabel, GroupLayout.PREFERRED_SIZE, 194, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 0, Short.MAX_VALUE))
				    .addGroup(thisLayout.createSequentialGroup()
				        .addComponent(resourcePanel, GroupLayout.PREFERRED_SIZE, 194, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 0, Short.MAX_VALUE))
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addGap(42)
				        .addComponent(buildButton, GroupLayout.PREFERRED_SIZE, 107, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 45, Short.MAX_VALUE)))
				.addContainerGap(19, 19));

	}
}
